<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/layui/2.5.7/css/layui.min.css">
</head>
<body>
<div class="layui-container">
    <div class="layui-layout layui-layout-admin ">



    <div class="layui-row">
        <div class="layui-col-md6 layui-col-md-offset3">
            <form class="layui-form" action="<?php echo url('doRegister'); ?>" method="post">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" lay-verify="required" placeholder="请输入用户名"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" lay-verify="required" placeholder="请输入密码"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="register">注册</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/layui/2.5.7/layui.min.js"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form;
        // 提交表单
        form.on('submit(register)', function (data) {
            $.post(data.form.action, data.field, function (res) {
                if (res.code === 1) {
                    layer.msg(res.msg, {icon: 1, time: 2000}, function () {
                        location.href = '<?php echo url("manage"); ?>';
                    });
                } else {
                    layer.msg(res.msg, {icon: 2, time: 2000});
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
